package com.wwdx;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author liguoliang
 * @version 2018-06-26 13:47:33
 */
@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages = { "com.wwdx.controller.rest" })
public class SwaggerConfig {

    @Value("#{constantProperties['server_evn']}")
    private boolean env;

	@Bean
	public Docket platformApi() {
	    //正式环境禁用swagger
		Docket docket = new Docket(DocumentationType.SWAGGER_2);
		if (env){
            return docket.pathMapping("/api/v2").apiInfo(apiInfo()).select().build();
        }
        return docket.select().paths(PathSelectors.none()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("蜜读-API").description("Copyright @ 2015-2018 北京唯我读秀文化有限公司")
				.contact(new Contact("midu","http://readerday.com/","liguoliang@readerday.com"))
                .license("Apache License Version 2.0")
                .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE").version("2.0").build();
	}
}